﻿using Bll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace Member_API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberController : ControllerBase
    {
        private readonly memberBll bll;

        public MemberController(memberBll bll)
        {
            this.bll = bll;
        }

        /// <summary>
        /// 会员信息录入
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostMemberAdd(T_MemberInfo info)
        {
            try
            {
                int res = bll.PostMemberAdd(info);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 查询数据显示
        /// </summary>
        /// <param name="name">会员姓名</param>
        /// <param name="phone">手机号</param>
        /// <param name="card">身份证号</param>
        /// <param name="code">卡号</param>
        /// <param name="createDate">创建时间</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMemberList(string? name, string? phone, string? card, string? code, DateTime createDate)
        {
            try
            {
                var list = bll.GetMemberList(name, phone, card, code, createDate);
                return Ok(new
                {
                    data = list
                });

            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
